package com.admin.business.portalWebsite.venusOaAdvertisingLocation;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 广告位置提示表
 * @create: 2023-11-22 16:07:28
 **/
@Service("venusOaAdvertisingLocationService")
@Slf4j
public class VenusOaAdvertisingLocationService{

    @Resource
    VenusOaAdvertisingLocationDao venusOaAdvertisingLocationDao;

    /**
     * 添加广告位置提示表,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - user_id:添加人
     *                   - type:类型 1:门户网 2:助业app 3:员工app 4:业主app
     *                   - name:位置名称
     *                   - image:图片
     *                   - content:内容
     *                   - money:金额
     *                   - begin_time:创建时间
     *                   - state:状态 0正常 1删除
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return addVenusOaAdvertisingLocation(CDO cdoRequest) {
        venusOaAdvertisingLocationDao.addVenusOaAdvertisingLocation(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新广告位置提示表数据
     *
     * @param cdoRequest - id:主键id
     *                   - user_id:添加人
     *                   - type:类型 1:门户网 2:助业app 3:员工app 4:业主app
     *                   - name:位置名称
     *                   - image:图片
     *                   - content:内容
     *                   - money:金额
     *                   - begin_time:创建时间
     *                   - state:状态 0正常 1删除
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return updateVenusOaAdvertisingLocationById(CDO cdoRequest) {
        venusOaAdvertisingLocationDao.updateVenusOaAdvertisingLocationById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除广告位置提示表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return deleteVenusOaAdvertisingLocationById(CDO cdoRequest){
        int count = venusOaAdvertisingLocationDao.deleteVenusOaAdvertisingLocationById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除广告位置提示表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return deleteVenusOaAdvertisingLocation(CDO cdoRequest) {
        int count = venusOaAdvertisingLocationDao.deleteVenusOaAdvertisingLocation(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取广告位置提示表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return getVenusOaAdvertisingLocationById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaAdvertisingLocationDao.getVenusOaAdvertisingLocationById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取广告位置提示表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return getVenusOaAdvertisingLocationListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaAdvertisingLocationDao.getVenusOaAdvertisingLocationListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaAdvertisingLocationDao.getVenusOaAdvertisingLocationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取广告位置提示表数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-22 16:07:28
     */
    @OpenApi
    public Return getVenusOaAdvertisingLocationListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaAdvertisingLocationDao.getVenusOaAdvertisingLocationListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaAdvertisingLocationDao.getVenusOaAdvertisingLocationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
